package nc.bs.hs.dmo;

import java.util.ArrayList;
import java.util.HashMap;

import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.bs.database.common.HsBaseDAO;
import nc.itf.hs.dmo.IHsDMO;
import nc.jdbc.framework.processor.ArrayListProcessor;
import nc.jdbc.framework.processor.ColumnProcessor;

public class HsDMO implements IHsDMO {
	private BaseDAO m_baseDAO = null;
	private BaseDAO getBaseDAO(){
		if(m_baseDAO == null){
			m_baseDAO = new HsBaseDAO().getOracleBaseDAO();
		}
		return m_baseDAO;
	}
	
	public Object findColValueByStrWhere(String tableName, String columnName,
			String strWhere) throws DAOException {
		StringBuilder sqlStrb = new StringBuilder("select ").append(columnName)
				.append(" from ").append(tableName).append(" where ").append(
						strWhere);
		return getBaseDAO().executeQuery(sqlStrb.toString(), new ColumnProcessor());
	}

	public HashMap<String, String> findColValuemapByStrWhere(String tableName, String columnName,
			String strWhere) throws DAOException {
		StringBuilder sqlStrb = new StringBuilder("select ").append(columnName)
				.append(" from ").append(tableName).append(" where ").append(
						strWhere);
		HashMap<String, String> map = new HashMap<String, String>();
		ArrayList list =  (ArrayList) getBaseDAO().executeQuery(sqlStrb.toString(), new ArrayListProcessor());
		for (int i = 0; i < list.size(); i++) {
			Object[] obj = (Object[]) list.get(i);
			map.put(obj[0].toString(), obj[0].toString());
		}
		return map;
	}
	
	
	

}
